import { Toast } from "vant"
import {
    getUserFriends,
    getUserGroups
} from "@/request/contacts-request"

export const useGetUserFriends = async (show,_id) => {
     show.value = true;
     try{
        const friends = await getUserFriends(_id);
        if(friends.code !== 201 || friends.message !== "success"){
            Toast("获取好友列表失败");
            show.value = false;
            return [];
        }else{
            show.value = false;
            return friends.data;
        }
     }catch(error){
        show.value = false;
        Toast("发生错误，错误信息：" + error.message);
     }
}


export const useGetUserGroups = async (show,_id) => {
    show.value = true;
    try{
       const groups = await getUserGroups(_id);
       if(groups.code !== 201 || groups.message !== "success"){
           Toast("获取群组列表失败");
           show.value = false;
           return [];
       }else{
           show.value = false;
           return groups.data;
       }
    }catch(error){
       show.value = false;
       Toast("发生错误，错误信息：" + error.message);
    }
}